<?php defined('_JEXEC') or die('Restricted access'); ?>

<form action="index.php" method="post" name="adminForm">
	
	<table>
		<tr>
			<td align="left" width="100%">
				<?php echo JText::_( 'Filter' ); ?>:
				<input type="text" name="search" id="search" value="<?php echo $this->lists['search']; ?>" class="text_area" onchange="document.adminForm.submit();" />
				<button onclick="this.form.submit();"><?php echo JText::_( 'Go' ); ?></button>
				<button onclick="document.getElementById('search').value='';this.form.getElementById('filter_state').value='';this.form.submit();"><?php echo JText::_( 'Reset' ); ?></button>
			</td>
			<td nowrap="nowrap">
				<?php echo $this->lists['state']; ?>
			</td>
		</tr>
	</table>
	
	<table class="adminlist">
	<thead>
		<tr>
			<th width="5">
				<?php echo JText::_( 'NUM' ); ?>
			</th>
			
			<th width="20">
				<input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count( $this->items ); ?>);" />
			</th>
			
			<th class="title" style="text-align: left;">
				<?php echo JText::_( 'NAME' ); ?>
			</th>
			
			<th class="title" style="text-align: left;">
				<?php echo JText::_( 'MANAGE PHOTOS' ); ?>
			</th>
			
			<th width="90" class="title">
				<?php echo JText::_( 'ID' ); ?>
			</th>
			
			<th width="90" class="title">
				<?php echo JText::_( 'AUTHOR' ); ?>
			</th>
			<!--
			<th width="150" class="title">
				<?php echo JText::_( 'PROFILE' ); ?>
			</th>
			-->
			<th width="150" class="title">
				<?php echo JText::_( 'PUBLISHED' ); ?>
			</th>
			
			<?php if( !empty($this->moderate) ): ?>
			<th width="5%" nowrap="nowrap">
				<?php echo JText::_( 'MODERATE' ); ?>
			</th>
			<?php endif; ?>
			
			<th width="100" nowrap="nowrap">
				<?php echo JText::_( 'ORDER' ); ?>
				<?php echo JHTML::_('grid.order', $this->items ); ?>
			</th>
		</tr>
	</thead>
<?php $footerColumns = empty($this->moderate) ? 10 : 11; ?>	
	<tfoot>
		<tr>
			<td colspan="<?php echo $footerColumns; ?>">
				<?php echo $this->pagination->getListFooter(); ?>
			</td>
		</tr>
	</tfoot>
	
	<tbody>	
    <?php
	$k = 0;
	
	for ($i=0; $i<count($this->items); $i++)
	{
		$row = &$this->items[$i];
		
		$checked 	= JHTML::_('grid.id', $i, $row->id );
		$published 	= JHTML::_('grid.published', $row, $i);
		$moderateImg 	= igHtmlHelper::moderateImage($row, $i, true);
		$editLink 	= JRoute::_( 'index.php?option=com_igallery&view=add_edit_category&cid[]='. $row->id );
		$manageLink 	= JRoute::_('index.php?option=com_igallery&controller=igphoto&catid='.$row->id);
		$profileLink 	= JRoute::_('index.php?option=com_igallery&controller=igprofile&view=add_edit_profile&cid='.$row->profile);
		
		$query = 'SELECT name FROM #__users where id = '.(int)$row->user;
		$this->db->setQuery($query);
		$author = $this->db->loadObject();
		
		if($author == null)
		{	
			$author = new stdClass();
			$author->name = '?';
		}
		
		$query = 'SELECT name FROM #__igallery_profiles where id = '.(int)$row->profile;
		$this->db->setQuery($query);
		$profile = $this->db->loadObject();
			
		$query = 'SELECT id FROM #__igallery_img where gallery_id = '.(int)$row->id;
		$this->db->setQuery($query);
		$this->db->query($query);
		$numPhotos = $this->db->getNumRows();
		
		?>
		<tr class="<?php echo "row$k"; ?>">
			<td>
				<?php echo $this->pagination->getRowOffset($i); ?>
			</td>
			
			<td>
				<?php echo $checked; ?>
			</td>
			
			<td>
				<a href="<?php echo $editLink ?>"><?php  echo $this->items[$i]->treename; ?></a>
			</td>
			
			<td>
				<a href="<?php echo $manageLink; ?>">
					<?php echo JText::_( 'MANAGE PHOTOS' ); ?> (<?php echo $numPhotos ?>)
				</a>
			</td>
			
			<td align="center">
				<?php echo $row->id;?>
			</td>
			
			<td align="center">
				<?php echo $author->name; ?>
			</td>
			<!--
			<td align="center">
				<a href="<?php echo $profileLink ?>"><?php echo $profile->name; ?></a>
			</td>
			-->
			<td align="center">
				<?php echo $published; ?>
			</td>
			
			<?php if( !empty($this->moderate) ): ?>
			<td align="center">
				<?php echo $moderateImg; ?>
			</td>	
			<?php endif; ?>
			
			<td class="order">
			<?php
			$showOrderUp = false;
			$showOrderDown = false;
			foreach($this->items as $key =>$value)
			{
				if ($row->parent == $value->parent && $row->ordering > $value->ordering)
				{
					$showOrderUp = true;
				}
				
				if ($row->parent == $value->parent && $row->ordering < $value->ordering)
				{
					$showOrderDown = true;
				}
			}
    		?>
			
				<span><?php echo $this->pagination->orderUpIcon($i, $showOrderUp, 'orderup', 'Move Up', true);?></span>
				<span><?php echo $this->pagination->orderDownIcon($i, count($this->items), $showOrderDown, 'orderdown', 'Move Down', true ); ?></span>
				<input type="text" name="order[]" size="5" value="<?php echo $row->ordering;?>" class="text_area" style="text-align: center" />
			</td>
			
		</tr>
		<?php
		$k = 1 - $k;
	}
	?>
</tbody>
</table>



<input type="hidden" name="option" value="com_igallery" />
<input type="hidden" name="task" value="" />
<input type="hidden" name="boxchecked" value="0" />
<input type="hidden" name="filter_order" value="<?php echo $this->lists['order']; ?>" />
<input type="hidden" name="filter_order_Dir" value="<?php echo $this->lists['order_Dir']; ?>" />
</form>

